//
//  NetWorkUtilsSwift.swift
//  Beadhouse
//
//  Created by Apple on 2018/10/25.
//  Copyright © 2018年 wangdong. All rights reserved.
//

import UIKit
import Alamofire
class NetWorkUtilsSwift: NSObject {

    
    func get(geturl:String,body:[String:Any],headerFile:[String:String],finished :@escaping (_ result : AnyObject?, _ error : NSError?)-> ()){
        Alamofire.request(geturl, method: .get, parameters: body, encoding: URLEncoding.default, headers: headerFile).responseJSON {
            (response)   in
           
            switch response.result{
                
            case .success(_):
                finished(response.result.value as AnyObject, nil)
            case .failure(_):
                finished(nil,response.result.error! as NSError)
            }
    }
 }
    
    
    
    func post(posturl:String,body:[String:Any],headerFile:[String:String],finished :@escaping (_ result : AnyObject?, _ error : NSError?)-> ()){
        
        Alamofire.request(posturl, method: .post, parameters: body, encoding: URLEncoding.default, headers: headerFile).responseJSON {
            (response)   in
            
            switch response.result{
                
            case .success(_):
                finished(response.result.value as AnyObject, nil)
            case .failure(_):
                finished(nil,response.result.error! as NSError)
            }
        }
        
        
    }
    
}
